<?php
namespace Mouta\AmistateBundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class ReindexarSolrCommand extends Command
{
    protected function configure()
    {
        $this
            ->setName('amistate:reindexarSolr')
            ->setDescription('Reindexar usarios en Solr')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
		$em = $this->getApplication()->getKernel()->getContainer()->get('doctrine')->getEntityManager();
		$usuarios = $em->getRepository('AmistateBundle:Usuario')->findBy(array('reindexar'=>true));
        foreach($usuarios as $usuario)
		{
			$usuario->setReindexar(false);
			$userManager = $this->getApplication()->getKernel()->getContainer()->get('fos_user.user_manager');
			$userManager->updateUser($usuario);
			$output->write('Usuario reindexado: '.$usuario->getId(),true);
		}
    }
}